package com.enterprise.dao.impl;

import com.enterprise.dao.BaseDao;
import com.enterprise.dao.ResourcesDao;
import com.enterprise.entity.Resources;
import com.enterprise.entity.page.PageModel;
import com.enterprise.util.DaoUtils;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;
import java.util.List;

@Repository("resourcesDao")
public class ResourcesDaoImpl implements ResourcesDao {

	@Resource
	private BaseDao dao;

	public void setDao(BaseDao dao) {
		this.dao = dao;
	}

	@Override
	public int insert(Resources resources) {
        Object resourcesid= dao.selectOne("resources.getResourcesid");
        resources.setResourcesid(DaoUtils.getMaxId(resourcesid));
        return dao.insert("resources.insert", resources);
	}

	@Override
	public int delete(Resources resources) {
		return dao.delete("resources.delete", resources);
	}

	@Override
	public int update(Resources resources) {
		return dao.update("resources.update", resources);
	}

	@Override
	public Resources selectOne(Resources resources) {
		return (Resources) dao.selectOne("resources.selectOne", resources);
	}

	@Override
	public PageModel selectPageList(Resources resources) {
		return dao.selectPageList("resources.selectPageList", "resources.selectPageCount", resources);
	}

	@Override
	public List<Resources> selectList(Resources resources) {
		return dao.selectList("resources.selectList", resources);
	}

	@Override
	public int deleteById(int id) {
		return dao.delete("resources.deleteById",id);
	}

	@Override
	public Resources selectById(int id) {
		return (Resources) dao.selectOne("resources.selectById",id);
	}

	@Override
	public List<Resources> getResourcesByName(String str) {
		return dao.selectList("resources.getResourcesByName",str);
	}

	@Override
	public List<Resources> getResourcesByPageId(Long pageId,Long roleId) {
		Resources resources = new Resources();
		resources.setRespageid(pageId);
		resources.setResourcesid(roleId);
		return dao.selectList("resources.getResourcesByPageId",resources);
	}

	@Override
	public PageModel selectPowerPageList(Resources resources) {
		return dao.selectPageList("resources.selectPowerPageList", "resources.selectPowerPageCount", resources);
	}
}
